﻿using System.Web.Mvc;
using MiserBlogData.Entities;
using System.Xml;
using System;
using NHibernate.Criterion;
using System.Collections.Generic;
using System.Linq;
using MiserBlogHelper.Extend;

namespace MiserBlogMVC.Controllers
{
    public class AccountController : Controller
    {
        //
        // GET: /Login/


        public ActionResult LogOn()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult LogOn(UserVIP user)
        {
            
            if (string.IsNullOrEmpty(user.Name))
            {
                ModelState.AddModelError("username", "请输入用户名");
            }
            if (string.IsNullOrEmpty(user.Pwd))
            {
                ModelState.AddModelError("userpwd", "请输入密码");
            }
            if (!ModelState.IsValid)
            {
                return View();
            }
            user.Pwd = user.Pwd.ToMD5String();
            UserVIP vip = user.Verify<UserVIP>();
            if (vip == null)
            {
                ModelState.AddModelError("usererror", "用户名或密码错误");
                return View();
            }
            else
            {
                vip.Role = (int)PersonRole.UserVIP;
                vip.CreateCookie(0);
                return RedirectToAction("index", "manage");
            }
        }

        /// <summary>
        /// 管理员登入验证
        /// </summary>
        /// <returns></returns>
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ManageVerify(UserVIP vip)
        {
            return View();
        }
    }
}
